﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using AutoMapper;
using CNav.Business.Services;
using CNav.Common;
using CNav.Domain;
using CNav.Model;

namespace CNav.DataApi.DataApi
{
    public class ComplaintTypeController : BaseApiController
    {
        [Authorize, HttpGet]
        public IList<ComplaintTypeModel> Get()
        {
            ResponseData<List<ComplaintType>> responseData = Service.Get<IComplaintService>().GetComplaintTypes();
            responseData.ValidateAndThrow();

            var complaintTypeModels = responseData.Data.Select(Mapper.Map<ComplaintTypeModel>).ToList();
            return complaintTypeModels;
        }

        [Authorize, HttpGet]
        public ComplaintType Get(int id)
        {
            var response = Service.Get<IComplaintService>().GetComplaintType(id);
            if (response.Data == null)
            {
                return new ComplaintType();
            }

            return response.Data;
        }
    }
}